package com.baize.baizeapp.test.sku

import android.content.Context
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.view.View
import android.widget.EditText
import android.widget.ImageView
import com.baize.baizeapp.R
import com.bumptech.glide.Glide

class SkuActivity : AppCompatActivity() {
    companion object{
        fun open(context: Context) {
            context.startActivity(Intent(context,SkuActivity::class.java))
        }
    }

    lateinit var tv_attribute: EditText
    lateinit var tv_sku: EditText
    lateinit var iv_image: ImageView

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_sku)
        tv_attribute = findViewById<EditText>(R.id.tv_attribute)
        tv_sku = findViewById<EditText>(R.id.tv_sku)
        iv_image = findViewById<ImageView>(R.id.iv_image)
        Glide.with(iv_image).load("https://img.heishiapp.com/FuM5LbaF7pVQFMEh0JLtcyLG_L9K-origin").into(iv_image)
    }

    fun onSelectSku(v: View) {
//        ProductSkuInfoDialogUtils.build(this)
//            .setMinHeight(0.5f)
//            .show()
        val liveProduct = LivebcProduct()
        liveProduct.title = "标题"
        liveProduct.brand = "032c"
        val attribute1 = LivebcProductAttribute()
        attribute1.name = "款式"
        attribute1.values = mutableListOf("A", "B", "C")
        val attribute2 = LivebcProductAttribute()
        attribute2.name = "尺码"
        attribute2.values = mutableListOf("大", "中", "小")
        val attribute3 = LivebcProductAttribute()
        attribute3.name = "颜色"
        attribute3.values = mutableListOf("红", "白", "蓝")
        liveProduct.attributes = mutableListOf(attribute1, attribute2, attribute3)
        val sku1 = LivebcProductSku()
        sku1.id = "111"
        sku1.stock = 2
        sku1.price = 11.0
        sku1.image_url = "https://img.heishiapp.com/Fu3VoiQaMPXLanmejZeYinMvyGvm-origin"
        sku1.attributes = mutableListOf(
            LivebcProductSkuAttribute("款式", "A"),
            LivebcProductSkuAttribute("尺码", "大"),
            LivebcProductSkuAttribute("颜色", "红")
        )
        val sku2 = LivebcProductSku()
        sku2.id = "222"
        sku2.stock = 6
        sku2.price = 22.0
        sku2.image_url = "https://img.heishiapp.com/Fu3VoiQaMPXLanmejZeYinMvyGvm-origin"
        sku2.attributes = mutableListOf(
            LivebcProductSkuAttribute("款式", "B"),
            LivebcProductSkuAttribute("尺码", "中"),
            LivebcProductSkuAttribute("颜色", "白")
        )
        liveProduct.skus = mutableListOf(sku1, sku2)
        liveProduct.min_price = 11.0
        liveProduct.max_price = 22.0
        liveProduct.image_urls = mutableListOf(
            "https://img.heishiapp.com/Fu3VoiQaMPXLanmejZeYinMvyGvm-origin",
            "https://img.heishiapp.com/Fu3VoiQaMPXLanmejZeYinMvyGvm-origin"
        )

        LiveShoppingDialogUtils.build(this)
            .setLivingProduct(liveProduct)
            .setClickBuyListener(object : OnClickProductBuyListener {
                override fun clickProductBuy(selectedLivebcProductSku: LivebcProductSku) {
                    Log.i("yanze_product", "clickProductBuy: ${selectedLivebcProductSku}")
//                        this.selectedLivebcProductSku = selectedLivebcProductSku
                }

                override fun clickProductImage(
                    title: String?,
                    imageList: ArrayList<String>,
                    position: Int
                ) {
                }

                override fun isShowLivingFloatDialog(isHidden: Boolean) {
                }
            }).show()

    }
}

class Attribute() {
    var name: String = ""
    var values: MutableList<String> = mutableListOf()
}

class Sku() {
    var id: String = ""
    var stock: Int = 0
    var price: Double = 0.0
    var title: String = ""
    var attributes: MutableList<Pair<String, String>> = mutableListOf()
}